<template>
  <div class="shopping_type items">
    <div class="toBtn toLeft" v-show="state.leftShow" @click="toLeft">
      <el-icon ><ArrowLeftBold /></el-icon>
    </div>
    <div class="toBtn toRight" v-show="state.rightShow" @click="toRight">
      <el-icon ><ArrowRightBold /></el-icon>
    </div>

    <div class="scrollListBox" ref="scrollListRef1"  @scroll="handleScroll">
      <div class="scroll-content">
        <div v-for="(item,index) of props.scrollList" class="item" :key="index" @click="toDetail(item.offer_id)">
          <img :src="item.first_img" alt="">
          <div class="markText">{{ item.min_price }}₽</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" name="Shopping_list" setup>
import {ref, reactive, defineProps, onMounted, defineEmits, watch} from 'vue'
import {ArrowLeftBold, ArrowRightBold} from "@element-plus/icons-vue";
import { useRouter } from 'vue-router'
const router = useRouter()
const emits = defineEmits(['clickTab'])
const scrollListRef1 = ref()
const props = defineProps({
  scrollList: {
    type: Array,
    default: () => {
      return []
    }
  },
  type: {
    type: String,
    default: '1'
  }
})
const state = reactive({
  leftShow: false,
  rightShow: true,
  index: -1,
  timer: undefined,
  listData: [],
  timeFunData: {}
})
const toRight = () => {
  scrollListRef1.value.scrollLeft += 500
  if (scrollListRef1.value.scrollWidth - scrollListRef1.value.scrollLeft <= 612) state.rightShow = false
  if (scrollListRef1.value.scrollLeft >= 0) state.leftShow = true
}
const toLeft = () => {
  scrollListRef1.value.scrollLeft -= 500
  if (scrollListRef1.value.scrollLeft <= 0) state.leftShow = false
  if (scrollListRef1.value.scrollWidth - scrollListRef1.value.scrollLeft > 612) state.rightShow = true
}
watch(() => props.scrollList, () => {

},{
  deep: true,
})

const toDetail = (topId:any) => {
  router.replace({
    path: '/product_detail',
    query:{
      top:topId
    }
  }).then(() => {
    window.location.reload()
  })

}

const handleScroll = () => {
  console.log(scrollListRef1)
}
onMounted(() => {

})



</script>

<style lang="less" scoped>
.shopping_type {
  position: relative;
  width: 100%;
  //height: 60px;
  //padding-top: 24px;
  //padding-bottom: 10px;

  .toBtn {
    width: 40px;
    height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background-color: white;
    top: 0;
  }

  .toLeft {
    position: absolute;
    left: -40px;
  }

  .toRight {
    position: absolute;
    right: -40px;
  }

  .scrollListBox::-webkit-scrollbar {
    display: none; /* WebKit */
  }

  .scrollListBox {
    width: 100%;
    overflow-x: auto;

    .scroll-content {
      display: flex;
      align-items: center;
    }

    .item {
      //background: #F3F6F8;
      margin-right: 16px;
      flex: 0 0 auto;
      cursor: pointer;
      img{
        width: 90px;
        height: 90px;
        border-radius: 8px;
      }
      .markText{
        font-family: Segoe UI, Segoe UI;
        font-weight: bold;
        font-size: 16px;
        color: #8444F7;
        line-height: 16px;
        text-align: center;
        font-style: normal;
        text-transform: none;
      }
    }
  }
}
</style>
